/*
 * Copyright 2008 gxlu, Inc. All rights reserved.
 * File name : BTSViewModel.java
 * Created on : Jan 19, 2009 5:56:11 AM
 * Creator : lethe
 */
package com.simplefan.meta.determine.demo.client.web.model;



import java.util.List;

import com.bstek.dorado.data.Dataset;
import com.bstek.dorado.data.ParameterSet;
import com.bstek.dorado.data.RecordIterator;
import com.bstek.dorado.view.data.ViewDataset;
import com.simplefan.meta.MetaDBManagerImpl;
import com.simplefan.meta.MetaObject;
import com.simplefan.meta.MetaObjectQueryResult;
import com.simplefan.meta.QueryCriteria;
import com.simplefan.meta.client.dorado.SupportMetaViewModel;
import com.simplefan.meta.determine.client.desktop.MetaPlatformClientContext;
import com.simplefan.meta.determine.client.desktop.service.MetaPlatformServiceFacade;
import com.simplefan.meta.help.MetaObjectHelper;

/**
 * <pre>
 * Description : TODO
 * @author simplefan
 * </pre>
 */
public class BTSViewModel extends SupportMetaViewModel {

	private MetaPlatformServiceFacade facade = null;

	public MetaPlatformServiceFacade getServiceFacade() {
		if (facade == null) {
			facade = MetaPlatformClientContext.getInstance().getServiceFacade();
		}
		return facade;
	}
	
	@Override
	protected void doLoadData(ViewDataset dataset) throws Exception {
		if(dataset.getId().equals("datasetBTS")){
			QueryCriteria criterial = new QueryCriteria(MetaObjectHelper.getMetaClass("com.simplefan.ne.BTS"));
			MetaObjectQueryResult result = MetaDBManagerImpl.getInstance().query(criterial);
			List<MetaObject>  metaList = result.getList();
			super.fromDO(metaList,dataset);
		}
		super.doLoadData(dataset);
	}
	
	@Override
	protected void doUpdateData(ParameterSet arg0, ParameterSet arg1) throws Exception {
		Dataset dataset = getDataset("datasetBTS");
		RecordIterator ri = dataset.recordIterator();
		ri.setVisibility(Dataset.FILTER_CHANGED);
		List<MetaObject> entityList = toDO(dataset, Dataset.FILTER_CHANGED);
		MetaDBManagerImpl.getInstance().persist(entityList);
		super.doUpdateData(arg0, arg1);
	}

}
